/* 
 *  <copyright file="IdCmp.cs" company="Wesley Jowitt">
 *  
 *  SobrietyEngine: Copyright (c) 2011 Wesley Jowitt
 *  
 *  This software is distributed under a software license.
 *   * As of the creation time of this file, the license in use is the Microsoft Permissive License (Ms-PL) 
 *    * The license can be viewed at:
 *     * License.Txt in the root folder of this project
 *      * http://sobrietyengine.codeplex.com/license
 *       * http://www.microsoft.com/opensource/licenses.mspx
 *       
 *  </copyright>
 *   */

using System;
using System.Collections.Generic;

using SobrietyEngine.Common;

namespace SobrietyEngine.Components.Common
{
    public class IdCmp:BaseComponent, IId, IComponent
    {
        string id = String.Empty;
        public string Id
        {
            get { return id; }
            set
            {
                if (id != String.Empty)
                    throw new Exception("ID has already been set");
                else id = value;
            }
        }

        public IdCmp()
            : this(String.Empty)
        {
        }

        public IdCmp(String name)
            : base()
        {
            Id = name;
        }

        override public void Set(Parameters parms)
        {
            Id = parms.GetValueAs<String>("ID", "MissingID");
        }

        public override List<ParameterDescription> GetParameterDescriptions()
        {
            List<ParameterDescription> pd = new List<ParameterDescription>();
            pd.Add(new ParameterDescription("ID", "Name of actor instance", typeof(String), "none"));
            return pd;
        }

        override public Type[] SupportedInterfaces()
        {
              return new Type[] { typeof(IId) };
        }

        public override Boolean InitComponent()
        {
            if (Id == String.Empty)
                Logging.Logger.GetSingleton().WriteError("IdComponent::Initialize() - ID set to none");
            return true;
        }

    }
}